package com.serverdemo.core.processor;

/**
 * 线程管理器
 * Created by wangqiang on 2020/4/10.
 */
public class ProcessorManager
{
    /**
     * 单例
     */
    private static final ProcessorManager instance = new ProcessorManager();

    /**
     * 登录线程
     */
    private AbstractProcessor loginProcessor;

    /**
     * 场景线程
     */
    private AbstractProcessor sceneProcessor;

    /**
     * db处理线程
     */
    private AbstractProcessor dbProcessor;

    /**
     * 世界线程
     */
    private AbstractProcessor worldProcessor;

    private ProcessorPool processorPool;

    public void initProcessorPool()
    {
        processorPool = new ProcessorPool();
        processorPool.init();
    }

    public ProcessorPool getProcessorPool()
    {
        return processorPool;
    }

    public static ProcessorManager getInstance()
    {
        return instance;
    }

    public AbstractProcessor getLoginProcessor()
    {
        return loginProcessor;
    }

    public void setLoginProcessor(AbstractProcessor loginProcessor)
    {
        processorPool.addProcessor(loginProcessor);
        this.loginProcessor = loginProcessor;
    }

    public AbstractProcessor getSceneProcessor()
    {
        return sceneProcessor;
    }

    public void setSceneProcessor(AbstractProcessor sceneProcessor)
    {
        processorPool.addProcessor(sceneProcessor);
        this.sceneProcessor = sceneProcessor;
    }

    public AbstractProcessor getDbProcessor()
    {
        return dbProcessor;
    }

    public void setDbProcessor(AbstractProcessor dbProcessor)
    {
        processorPool.addProcessor(dbProcessor);
        this.dbProcessor = dbProcessor;
    }

    public AbstractProcessor getWorldProcessor()
    {
        return worldProcessor;
    }

    public void setWorldProcessor(AbstractProcessor worldProcessor)
    {
        processorPool.addProcessor(worldProcessor);
        this.worldProcessor = worldProcessor;
    }

    public void sendMessage(AbstractProcessor dstProcessor, AbstractProcessorMessage message)
    {
        dstProcessor.receiveMessage(message);
    }
}
